# 抖码算法，让算法学习变得简单有趣
# 作者：老汤


n = int(input())
board = [[''] * n for _ in range(n)]
for i in range(n):
    chars = str(input()).split(",")
    for j in range(n):
        board[i][j] = chars[j]
word = str(input())

dirs = [[-1, 0], [1, 0], [0, -1], [0, 1]]
rows, cols = len(board), len(board[0])
visited = [[False] * cols for _ in range(rows)]
res = []


# list_ 记住符合单词顺序的字符对应的下标值
def dfs(row, col, index, list_) -> bool:
    if board[row][col] != word[index]:
        return False
    elif index == len(word) - 1:
        # 找到了符合单词顺序的所有字符
        list_.append([row, col])
        global res
        res = list_[0:len(list_)]
        return True

    # 将当前字符所在的索引放入结果集
    list_.append([row, col])
    visited[row][col] = True
    for d in dirs:
        next_row, next_col = row + d[0], col + d[1]
        if 0 <= next_row < rows and 0 <= next_col < cols and not visited[next_row][next_col]:
            if dfs(next_row, next_col, index + 1, list_):
                return True
    # 回溯
    list_.pop()
    visited[row][col] = False
    return False


for row in range(rows):
    has_found = False
    for col in range(cols):
        if board[row][col] == word[0]:
            if dfs(row, col, 0, []):
                has_found = True
                break
    if has_found:
        break

for i in range(len(res)):
    print(str(res[i][0]) + ",", end="")
    if i == len(res) - 1:
        print(str(res[i][1]), end="")
    else:
        print(str(res[i][1]) + ",", end="")
print("")